package mini.expr;

import java.util.HashMap;

import mini.Program;
import mini.compiler.CodeGenerator;

public class Ident extends Expr {

    private String name;

    public Ident(String s){
    	super();
    	name = s;
    }

    public Integer eval(HashMap hm){
    	return new Integer(hm.get(name).toString());
    }
    
    /**
     * Routine is from slide 10
     * Load variable from constant table value.
     * Store variable in temp variable in memory
     */
    public String parse(HashMap hm) {
    	
    	// Store the named variable, and temp variable, to the symbl table
    	hm.put(getTempVariable(), null);
    	hm.put(name, null);
    	
    	// We always have to generate code
    	CodeGenerator cg = new CodeGenerator();
    	cg.addLoadAccumulator( name );
    	cg.addStoreAccumulator( getTempVariable() );    	
		return cg.getCode();
    }

	@Override
	public String toString() {
		return "Ident [name=" + name + "]";
	}
}
